package com.gee.spring.boot.rpf.client.gzaddr;

import com.gee.spring.boot.rpf.client.gaode.GaoDeResponse;
import com.gee.spring.boot.rpf.controller.fico.RequestWrapper;
import com.gee.thread.flow.common.result.ExecuteState;
import com.gee.thread.flow.common.result.WorkResult;
import com.gee.thread.flow.executor.ExecuteContext;
import com.gee.thread.flow.translator.V2PTranslator;
import org.springframework.stereotype.Component;

/**
 * desc:
 *
 * @author gee wrote on  2021-02-03 17:07:12
 */
@Component
public class GzAddrRequestInitializer implements V2PTranslator<RequestWrapper, GzAddrRequest> {

    @Override
    public GzAddrRequest translate(String preWorkId, ExecuteContext<RequestWrapper> executeContext) {
        GzAddrRequest request = new GzAddrRequest();
        WorkResult<?, ?> gaoDeWorkResult = executeContext.getWorkResult("GaoDe");
        if (gaoDeWorkResult.getExecuteState().get() == ExecuteState.SUCCESS.getCode()){
            GaoDeResponse gaoDe = executeContext.getResult("GaoDe", GaoDeResponse.class);
            request.setLat(gaoDe.getLat());
            request.setLot(gaoDe.getLot());
        }
        return request;
    }
}
